home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
PredatorPrey
/
ParseDataString.c
< prev
next >
Wrap
Text File
|
1996-06-22
|
2KB
|
111 lines
/* ParseDataString.c */
#ifndef __C14__
#include "PredatorPrey.h"
#endif
#include "ParseDataString.h"
#include <fp.h>
double_t ParseDataString(Str255 dString,short selector,short *conNum)
{
double_t result,mResult,eResult,result4,result5;
double_t temp,mTemp,eTemp,bTemp;
char manStr[12];
char expStr[3];
char baseStr[3];
char outStr[16];
decimal result6,result7,result8,result9;
short expLen,conVal,i,vp,start = 0;
Boolean floatTyp = 0;
Boolean qHasPoint = 0;
Boolean negExp = 0;
Boolean posExp = 0;
short ePlace = 0;
short ptPlace = 0;
short expPlace = 0;
for(i = 1;i <= dString[0];i++)
{
if(dString[i] == 'e' || dString[i] == 'E')
{
floatTyp = 1;
ePlace = i;
}
if(dString[i] == '.')
{
qHasPoint = 1;
ptPlace = i;
}
if(dString[i] == '-')
{
negExp = 1;
expPlace = i;
}
if(dString[i] == '+')
{
posExp = 1;
expPlace = i;
}
}
if(floatTyp)
{
for(i = 0;i < ePlace - 1;i++)
{
manStr[i] = dString[i + 1];
}
manStr[0] = ePlace - 1;
if(negExp || posExp)
{
expLen = dString[0] - expPlace;
for(i = 0;i < expLen;i++)
{
expStr[i] = dString[expPlace + 1 + i];
}
}
else
{
expLen = dString[0] - ePlace;
for(i = 0;i < expLen;i++)
{
expStr[i] = dString[ePlace + 1 + i];
}
}
str2dec(manStr,&start,&result7,&vp); /* new */
mTemp = dec2num(&result7); /* new */
start = 0;
str2dec(expStr,&start,&result8,&vp); /* new */
eTemp = dec2num(&result8); /* new */
bTemp = 10;
eResult = pow(bTemp,eTemp); /* eResult is type double_t */
if(negExp)
{
temp = mTemp / eResult;
}
else
{
temp = mTemp * eResult;
}
}
else
{
if(qHasPoint)
{
;
}
else
{
dString[++dString[0]] = '.';
dString[++dString[0]] = '0';
}
for(i = 0;i <dString[0];i++)
{
outStr[i] = dString[i + 1];
}
str2dec(outStr,&start,&result6,&vp);
temp = dec2num(&result6); /* new */
}
return(temp);
} /* end of ParseDataString */